package net.moao.netutils.customView;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import net.moao.netutils.R;

import java.util.List;
import java.util.Map;

public class HeadersMapAdapter extends ArrayAdapter<Map.Entry<String, String>> {
    private Context context;
    private List<Map.Entry<String, String>> entries;

    public HeadersMapAdapter(Context context, int resource, List<Map.Entry<String, String>> entries) {
        super(context, resource, entries);
        this.context = context;
        this.entries = entries;
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        if (convertView == null) {
//            convertView = LayoutInflater.from(context).inflate(android.R.layout.simple_list_item_2, parent, false);
            convertView = LayoutInflater.from(context).inflate(R.layout.list_item_header, parent, false);
        }

//        TextView text1 = convertView.findViewById(android.R.id.text1);
//        TextView text2 = convertView.findViewById(android.R.id.text2);
        TextView textKey = convertView.findViewById(R.id.text_key);
        TextView textValue = convertView.findViewById(R.id.text_value);

        Map.Entry<String, String> entry = entries.get(position);
        textKey.setText(entry.getKey());
        textValue.setText(entry.getValue());

        return convertView;
    }
}